#ifndef COMPUTEJOINTVERTEXOFLINEANDPLANE_H
#define COMPUTEJOINTVERTEXOFLINEANDPLANE_H

#include "geometry/wsyline.h"
#include "geometry/wsyplane.h"

/** 计算线段与平面的交点 */
GLfloat *ComputeJointVertexOfLineAndPlane(WSYLine *line, WSYPlane *plane) {
    GLfloat *lineVertex = line->getVertex();
    GLfloat *lineDirection = line->getDirection();

    GLfloat *planeVertex = plane->getVertex();
    GLfloat *planeNormal = plane->getNormal();

    GLfloat x0 = lineVertex[0], y0 = lineVertex[1], z0 = lineVertex[2];
    GLfloat a = lineDirection[0], b = lineDirection[1], c = lineDirection[2];

    GLfloat A = planeNormal[0], B = planeNormal[1], C = planeNormal[2];
    GLfloat D = plane->getDValue();

    GLfloat t = -(A*x0 + B*y0 + C*z0 + D) / (A * a + B * b + C * c);
    return Math3D::newInstanceWithValue(a * t + x0, b * t + y0, c * t + z0);
}

#endif // COMPUTEJOINTVERTEXOFLINEANDPLANE_H
